home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / prog / rukc10.zip / X01M.C < prev    next >
C/C++ Source or Header  |  1993-03-06  |  4KB  |  161 lines

  1.  
  2. #include <dos.h>
  3. #include <conio.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdarg.h>
  7.  
  8. #include "ruckmidi.h"
  9.  
  10. /*
  11. X02M.c 28-Feb-93 chh
  12. Load & Play MIDI file
  13. */
  14.  
  15. /*
  16. The following structures are in ruckmidi.h
  17. */
  18.  
  19. extern struct MidiDataArea __pascal MIDIDATA;
  20.  
  21. struct SysInfoMidiPack SIMP;
  22. struct InitMidiPack IMP;
  23. struct XitMidiPack XMP;
  24. struct LoadMidiPack LMP;
  25. struct SetMidiPack SMP;
  26. struct SetFMProPack SFMPP;
  27. struct PlaybackMidiPack PBMP;
  28. struct OutMsgMidiPack OMMP;
  29. struct DeallocMidiPack DMP;
  30.  
  31. int rez, rez2;      /* result status codes */
  32. char nums[9] = {7}; /* number buffer for _cgets()*/
  33. char filename[81];  /* pathname to load */
  34.  
  35.  
  36. int main()
  37. {
  38.  
  39.     unsigned i=0;
  40.  
  41.     printf("\nX01M.C - RUCKUS-MIDI load & play of file example. [930228]\n");
  42.  
  43.     /*
  44.     Initialize RUCKMIDI and device and register ExitMidi with _atexit
  45.     */
  46.  
  47.     IMP.Func = InitMidi;
  48.     IMP.DeviceID = 1;           /* OPL-2 percussive mode */
  49.     IMP.IOport = 0x388;
  50.  
  51.     if (IMP.DeviceID == 1) {
  52.        IMP.ChMask = 0x23F;      /* mask for channels 0-5, 9 */
  53.        IMP.PercCh = 9;
  54.     }
  55.     else {
  56.        IMP.ChMask = 0x1FF;      /* mask for channels 0-8 */
  57.        IMP.PercCh = 0;
  58.     }
  59.  
  60.     IMP.Flags = 0;
  61.     rez = RUCKMIDI(&IMP);       /* Initialize */
  62.     if (rez == 0) {
  63.  
  64.         XMP.Func = AtExitMidi;
  65.         rez2 = RUCKMIDI(&XMP);
  66.         if (rez2 != 0) {
  67.             printf("AtExitMidi failed, press Enter to continue");
  68.             getchar();
  69.         }
  70.  
  71.         /*
  72.         Increase SB Pro main and FM vol volumes to max
  73.         */
  74.  
  75.         SFMPP.Func = SetAllFMSBP;
  76.         SFMPP.IOport = 0x220;       /* if there it'll respond */
  77.         SFMPP.MasterVol = 0x0F0F;   /* if not, no problem */
  78.         SFMPP.Steer = 0;
  79.         SFMPP.FMvol = 0x0F0F;
  80.         rez2 = RUCKMIDI(&SFMPP);
  81.  
  82.  
  83.         /*
  84.         Set patch map to GM or MT-32, here I'll use GM (jazz.mid is GM)
  85.         */
  86.  
  87.         SMP.Func = SetPatchMidi;
  88.         SMP.PatchMapID = 0;     /* actually, this is the GM is the default */
  89.         SMP.PatchMapPtr = NULL;
  90.         rez2 = RUCKMIDI(&SMP);
  91.  
  92.         if (SMP.PatchMapID==0)
  93.             puts("Using General MIDI map");
  94.         else
  95.             puts("Using MT-32 MIDI map");
  96.  
  97.         /*
  98.         Load a single MIDI file and play it
  99.         */
  100.  
  101.         if (rez == 0) {
  102.             /* load file and setup playback parameters */
  103.             /* rez==0 always in this example */
  104.  
  105.             printf("\nMIDI filename: ");
  106.             gets(filename);
  107.  
  108.             LMP.Func = LoadMidi;
  109.             LMP.FilenamePtr = filename;
  110.             LMP.StartPos = 0L;          /* start at first byte */
  111.             LMP.LoadSize = 0L;          /* autoload entire file */
  112.             rez = RUCKMIDI(&LMP);
  113.             if (rez == 0) {
  114.  
  115.                 printf("K bytes left: %u\n",MIDIDATA.MemDOS);
  116.                 printf("K bytes used: %u\n",MIDIDATA.MemUsed);
  117.  
  118.                 PBMP.Func = PlayMidi;
  119.                 PBMP.Mode = 1;          /* background mode a must */
  120.                 PBMP.LoadPtr = LMP.LoadPtr;
  121.                 rez = RUCKMIDI(&PBMP);
  122.  
  123.                 if (rez == 0) {
  124.                     do
  125.                        printf("\rCurrent tick: %lx",MIDIDATA.TickCount);
  126.                     while ( MIDIDATA.End == 0);
  127.  
  128.                     /*
  129.                     End play
  130.                     */
  131.  
  132.                     XMP.Func = EndMidi;
  133.                     rez2 = RUCKMIDI(&XMP);
  134.                 }
  135.                 else {
  136.                     printf("Play failed, %u\n",rez);
  137.  
  138.                 /*
  139.                 Release memory/handle used by LoadMidi
  140.                 (ExitMidi would do this, too)
  141.                 */
  142.  
  143.                 DMP.Func = DeallocMidi;
  144.                 DMP.HandSeg = _FP_SEG(LMP.LoadPtr);
  145.                 DMP.TypeFlag = 0;
  146.                 rez = RUCKMIDI(&DMP);  /* should error check in procode */
  147.                 }
  148.             }
  149.             else
  150.                 printf("Load failed, %u\n", rez);
  151.         }  /* rez==0 always if*/
  152.     }
  153.     else
  154.         printf("Initialization failed, %u\n", rez);
  155.  
  156. XMP.Func = ExitMidi;
  157. rez = RUCKMIDI(&XMP);
  158. return(rez);
  159.  
  160. }
  161.